// import { Process, Exception, time } from "./__types/yao";

function beforeSave(payload) {
  var id = Process("session.Get", "user_id");
  payload["user_id"] = id;
  console.log("beforeSave-payload-->", payload);
  return [payload];
}


function GetPersonalIntegral() {
  let user_id = Process("session.Get", "user_id");
  if (!user_id) { throw new Exception("请提供查询用户", 400); }
  // user_id = 3;
  var query = new Query();
  var data = query.Get({
    select: ["user_id", ":SUM(points) as total"],
    from: "integral",
    wheres: [{ ':deleted_at': '删除', '=': null }, { ':user_id': '用户', '=': user_id }],
    groups: [{ field: "user_id", comment: "按用户统计" }],
  });
  if (data.length > 0) {
    return data[0];
  } else {
    return { "total": 0, "user_id": user_id, };
  }
}

